package com.kedacom.demo.springrabbitex.ack.producer;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.kedacom.demo.springrabbitex.Message;
import com.kedacom.demo.springrabbitex.RabbitMessageSender;

public class AckProducer {

	public static void main(String[] args) throws InterruptedException {
		Runner runner1 = new Runner();
		runner1.start = 1;
		runner1.count = 100;
		new Thread(runner1).start();

		Runner runner2 = new Runner();
		runner2.start = 1001;
		runner2.count = 100;
		new Thread(runner2).start();

		Thread.sleep(10000);
		System.exit(1);
	}

	static class Runner implements Runnable {

		ClassPathXmlApplicationContext context;
		RabbitMessageSender rabbitMessageSender;
		int start;
		int count;

		public Runner() {
			context = new ClassPathXmlApplicationContext("/springrabbitex/spring-rabbitmq-ack-producer.xml");
			rabbitMessageSender = context.getBean(RabbitMessageSender.class);
		}

		public void run() {
			for (int i = start; i < start + count; i++) {
				rabbitMessageSender.convertAndSend(new Message("test ack msg " + i), true);
			}
		}
	}

}
